package com.sunlee.common.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sunlee.common.core.entity.BaseEntity;
import com.sunlee.common.core.entity.PageData;
import com.sunlee.common.service.dao.MarketingProductMappingDao;
import com.sunlee.common.service.dto.MarketingProductInfoDTO;
import com.sunlee.common.service.dto.MarketingProductMappingDTO;
import com.sunlee.common.service.entity.MarketingProductMappingEntity;
import com.sunlee.common.service.service.MarketingProductMappingService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 营销商品表
 */
@Service
public class MarketingProductMappingServiceImpl extends CrudServiceImpl<MarketingProductMappingDao, MarketingProductMappingEntity, MarketingProductMappingDTO> implements MarketingProductMappingService {

    @Override
    public PageData<MarketingProductInfoDTO> pageRelatedProduct(Map<String, Object> params, long id, Long pId, String title, int type) {
        IPage<MarketingProductInfoDTO> page = baseDao.pageRelatedProduct(
                getPage(params, null, false),
                id,
                pId,
                title,
                type);
        return getPageData(page, MarketingProductInfoDTO.class);
    }

    @Override
    public Integer deleteByPIdAndCId(Long marketingId, Long[] ids) {
        return baseDao.delete(new LambdaQueryWrapper<MarketingProductMappingEntity>()
                .eq(MarketingProductMappingEntity::getMarketingId, marketingId)
                .in(MarketingProductMappingEntity::getProductId, Arrays.asList(ids)));
    }

    @Override
    public void deleteByPIds(List<Long> pIds) {
        baseDao.delete(new LambdaQueryWrapper<MarketingProductMappingEntity>().in(MarketingProductMappingEntity::getProductId, pIds));
    }

    @Override
    public void deleteByMIds(List<Long> mIds) {
        baseDao.delete(new LambdaQueryWrapper<MarketingProductMappingEntity>().in(MarketingProductMappingEntity::getMarketingId, mIds));
    }

    @Override
    public Boolean updateSort(Long id, Integer sort) {
        return baseDao.updateSort(id, sort);
    }
}




